
<?php	
	include "curl.php";
	if(isset($_POST['name'])){
		$name = $_POST['name'];
		$password = $_POST['password'];			
		
		$token = getToken($name,$password);
		$tenants = getTenants($token);
	}
	if(isset($_POST['tenants_Index'])){		
		$token = $_POST['token'];
		$tenants = getTenants($token);
		$tenantToken = getTenantstoken($tenants[$_POST['tenants_Index']]['name'],$_POST['token']);
		//print_r($tenants);
		$compute_limits = getCompute_limits($tenants[$_POST['tenants_Index']]['id'],$tenantToken);
		$blockstorage_limits = getBlockstorage_limits($tenants[$_POST['tenants_Index']]['id'],$tenantToken);
	}	
		
?>

<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<script language='javascript'>
			
			function post(path, params, method) {
				method = method || "post"; // Set method to post by default if not specified.

				// The rest of this code assumes you are not using a library.
				// It can be made less wordy if you use one.
				var form = document.createElement("form");
				form.setAttribute("method", method);
				form.setAttribute("action", path);

				for(var key in params) {
					if(params.hasOwnProperty(key)) {
						var hiddenField = document.createElement("input");
						hiddenField.setAttribute("type", "hidden");
						hiddenField.setAttribute("name", key);
						hiddenField.setAttribute("value", params[key]);

						form.appendChild(hiddenField);
					 }
				}

				document.body.appendChild(form);
				form.submit();
			}
			
			function val(){
				var tenant_index = document.getElementById("select1").value;				
				//document.getElementById("txtHint").innerHTML = tenant_index;
				
				post('login.php',{token:'<?php echo $token;?>',tenants_Index:tenant_index});
			}
		</script>
	</head>
	<body>
		
		<?php
		
			echo '<select id="select1">';
			$i=0;
			foreach($tenants as $value){
				echo '<option value="'.$i.'" >'.$value['name'].'</option>';
				$i++;
			}
			echo '</select></br>';
			
		?>
		
		<button onclick='val()'>確定</button>
		<div id="txtHint">
			<?php
				if(isset($compute_limits)){
					echo '<p>Tenant Name：'.$tenants[$_POST["tenants_Index"]]["name"].'</p>';
					echo '<p>Instances：Used '.$compute_limits["totalInstancesUsed"].' of '.$compute_limits["maxTotalInstances"].'</p>';
					echo '<p>VCPUs ： Used '.$compute_limits["totalCoresUsed"].' of '.$compute_limits["maxTotalCores"].'</p>';
					echo '<p>RAM ： Used '.$compute_limits["totalRAMUsed"].' of '.$compute_limits["maxTotalRAMSize"].'</p>';
					echo '<p>Floating IPs ： Used '.$compute_limits["totalFloatingIpsUsed"].' of '.$compute_limits["maxTotalFloatingIps"].'</p>';
					echo '<p>Security Groups ： Used '.$compute_limits["totalSecurityGroupsUsed"].' of '.$compute_limits["maxSecurityGroups"].'</p>';
					echo '<p>Volumes ： Used '.$blockstorage_limits["totalVolumesUsed"].' of '.$blockstorage_limits["maxTotalVolumes"].'</p>';
					echo '<p>Volume Storage ： Used '.$blockstorage_limits["totalGigabytesUsed"].' of '.$blockstorage_limits["maxTotalVolumeGigabytes"].'</p>';
				}
			?>
		</div>
	</body>
</html>
